package com.glela.controller;

import com.alibaba.fastjson.JSONObject;
import com.glela.live.model.LiveRecFile;
import com.glela.live.service.LiveRecFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/liveRecNotify")
public class LiveRecNotifyController extends LiveBaseController{

    @Autowired
    private LiveRecFileService liveRecFileService;

    @RequestMapping("/add")
    public String add(@RequestBody JSONObject jsonObject){
        String domain = jsonObject.getString("domain");
        String app = jsonObject.getString("app");
        String stream = jsonObject.getString("stream");
        String uri = jsonObject.getString("uri");
        String duration = jsonObject.getString("duration");
        String start_time = jsonObject.getString("start_time");
        String stop_time = jsonObject.getString("stop_time");
        LiveRecFile liveRecFile = new LiveRecFile();
        liveRecFile.setDomain(domain);
        liveRecFile.setApp(app);
        liveRecFile.setLivePlanId(Integer.valueOf(stream));
        liveRecFile.setUri(uri);
        liveRecFile.setDuration(new BigDecimal(duration));
        liveRecFile.setStartTime(Long.valueOf(start_time));
        liveRecFile.setStopTime(Long.valueOf(stop_time));
        int count = liveRecFileService.add(liveRecFile);
        return count+"";
    }
}
